package hashSet1;

import java.util.*;

public class HashSetDemo {
	public static void main(String[] args) {
		Set<NewsTitle> newsTitle = new <NewsTitle>HashSet();
		NewsTitle title1 = new NewsTitle(1, "财经", "admin");
		NewsTitle title2 = new NewsTitle(2, "娱乐", "admin");
		NewsTitle title3 = new NewsTitle(3, "民生", "admin");
		newsTitle.add(title1);
		newsTitle.add(title2);
		newsTitle.add(title3);

		// 获取新闻标题的总数
		System.out.println("新闻标题总数量是：" + newsTitle.size());

		// 方法一：用增强型for逐条打印每条新闻标题的名称
		for (NewsTitle news : newsTitle) {
			System.out.println(news.getId() + "-" + news.getNewsName() + "-" + news.getCreator());
		}

		System.out.println("***************************");

		// 方法二：用iterator迭代器for逐条打印每条新闻标题的名称
		Iterator<NewsTitle> iterator = newsTitle.iterator();
		while (iterator.hasNext()) {
			NewsTitle news = iterator.next();
			System.out.println(news.getId() + "-" + news.getNewsName() + "-" + news.getCreator());
		}
	}
}
